package com.small.site.vo.req;

import com.small.site.pojo.SysRole;
import com.small.site.validation.ValidationType;
import com.small.site.vo.BaseForm;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;

/**
 * @author xiaochi
 * @date 2021/12/16 15:16
 * @desc RoleReqVo
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RoleReqVo extends BaseForm<SysRole> {

    @NotBlank(message = "角色 id 不能为空",groups = ValidationType.update.class)
    private String id;

    @NotBlank(message = "角色名称不能为空")
    @Length(min = 2,max = 15,message = "角色名称长度为2 ~ 15个字符")
    private String name;

    private String description;// 角色描述

    private Integer status;// 角色状态：1:正常0:弃用

    private List<String> permissionsIds;// 选择的权限id集合

    /**
     * 获取实例
     * @return 返回实体类
     */
    @Override
    public SysRole buildEntity() {
        SysRole sysRole = new SysRole();
        BeanUtils.copyProperties(this,sysRole);
        if (StringUtils.isEmpty(this.id)){
            sysRole.setCreateTime(new Date());
            sysRole.setUpdateTime(new Date());
        }else{
            sysRole.setUpdateTime(new Date());
        }
        return sysRole;
    }
}
